#pragma once

#include <gtl/script/script.h>

namespace gtl
{

namespace dui
{

template<class T>
class effects
{
protected:
	typedef effects<T> effects_type;

protected:
	effects()
	{
	}

protected:
	void create_effect(gtl::xml& node)
	{
		gtl::xml* effect = node[_T("effects")];
		if(effect == NULL)
			return;

		const gtl::xml::attribs_type& attribs = effect->attribs();
		for(size_t i = 0; i < attribs.size(); ++i)
		{
			if(attribs[i].first.icmp(_T("clip")))
				continue;

			m_effects[attribs[i].first] = attribs[i].second;
		}
	}

	void run_effect(const gtl::tchar* efft)
	{
		if(efft == NULL)
			return;

		std::map<gtl::tstr, gtl::tstr>::iterator ite = m_effects.find(efft);
		if(ite == m_effects.end())
			return;

		gtl::script* scrpt = NULL;
		static_cast<T*>(this)->visit(&visitor_get_script(scrpt));
		if(scrpt == NULL)
			return;

		scrpt->eval(gtl::str_warp((*ite).second));
	}

protected:
	std::map<gtl::tstr/*name*/, gtl::tstr/*script code*/> m_effects;
};

} // end of namespace dui

} // end of namespace gtl